package com.jumei.flume.sink.kudu;

import java.util.List;
import java.util.Map;

/**
 * Created by ZhongGang
 * at 2018/10/15 14:17
 * <p>
 * 双写KUDU
 */
public class MultiKuduJdbcDaoImpl implements KuduJdbcDao {

    private List<KuduJdbcDaoImpl> kuduJdbcDaoList;

    public MultiKuduJdbcDaoImpl(List<KuduJdbcDaoImpl> kuduJdbcDaoList) {
        this.kuduJdbcDaoList = kuduJdbcDaoList;
    }

    @Override
    public int upsert(String table, List<Map<String, Object>> records) throws Exception {
        int result = 0;
        for (KuduJdbcDaoImpl kuduJdbcDao : kuduJdbcDaoList) {
            result = kuduJdbcDao.upsert(table, records);
        }
        return result;
    }

    @Override
    public boolean upsert(String table, Map<String, Object> record) throws Exception {
        boolean result = false;
        for (KuduJdbcDaoImpl kuduJdbcDao : kuduJdbcDaoList) {
            result = kuduJdbcDao.upsert(table, record);
        }
        return result;
    }

    @Override
    public <T> int upsert(List<T> records) throws Exception {
        int result = 0;
        for (KuduJdbcDaoImpl kuduJdbcDao : kuduJdbcDaoList) {
            result = kuduJdbcDao.upsert(records);
        }
        return result;
    }

    @Override
    public <T> boolean upsert(T record) throws Exception {
        boolean result = false;
        for (KuduJdbcDaoImpl kuduJdbcDao : kuduJdbcDaoList) {
            result = kuduJdbcDao.upsert(record);
        }
        return result;
    }

    @Override
    public <T> int delete(List<T> records) throws Exception {
        int result = 0;
        for (KuduJdbcDaoImpl kuduJdbcDao : kuduJdbcDaoList) {
            result = kuduJdbcDao.delete(records);
        }
        return result;
    }

    @Override
    public <T> boolean delete(T record) throws Exception {
        boolean result = false;
        for (KuduJdbcDaoImpl kuduJdbcDao : kuduJdbcDaoList) {
            result = kuduJdbcDao.delete(record);
        }
        return result;
    }

    @Override
    public int delete(String table, List<Map<String, Object>> records) throws Exception {
        int result = 0;
        for (KuduJdbcDaoImpl kuduJdbcDao : kuduJdbcDaoList) {
            result = kuduJdbcDao.delete(table, records);
        }
        return result;
    }

    @Override
    public int delete(String table, Map<String, Object> record) throws Exception {
        int result = 0;
        for (KuduJdbcDaoImpl kuduJdbcDao : kuduJdbcDaoList) {
            result = kuduJdbcDao.delete(table, record);
        }
        return result;
    }
}
